import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { resolve } from "path"
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig(({ command, mode }) => ({
  base: "/blue-low-code/",
  server: {
    port: 4444,
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: "http://127.0.0.1:8083",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
  define: {
    // _VUE_OPTIONS_API_: JSON.stringify(false),
  },
  assetsInclude: [],
  build: {
    cssCodeSplit: false,
    chunkSizeWarningLimit: 1024,

    // rollupOptions: {
    //   output: {
    //     manualChunks(id) {
    //       if (id.includes("node_modules")) {
    //         return id.toString().split("node_modules/")[1].split("/")[0].toString()
    //       }
    //     },
    //   },
    // },
  },
  // server: {
  //   port: 3333,
  //   proxy: {
  //     "/Api/": "https://fuyouplus.cn",
  //   },
  // },
  plugins: [
    vue({
      template: {
        compilerOptions: {
          // 将所有包含短横线的标签作为自定义元素处理
          // isCustomElement: tag => tag.includes("my-"),
        },
      },
    }),
    vueJsx()
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/styles/index.module.scss";`, //全局混入scss
      },
    },
  },
  resolve: {
    extensions: [".js", ".ts", ".tsx", ".jsx"],
    alias: [
      //配置路径别名
      { find: "@", replacement: resolve(__dirname, "src") },
      { find: "@cop", replacement: resolve(__dirname, "src/components") },
      { find: "@api", replacement: resolve(__dirname, "src/api") },
    ],
  },
}))
